#!/bin/bash

echo "build ..."
rm -rf output/*
mkdir -p output
# export MAVEN_OPTS='-Xms256m -Xmx768m'
if [ "ci" = $1 ] ; then
    mvn clean compile -U -pl itrms/itrms-base,itrms/itrms-bundle -am -Dbdgc.skip=false
elif [ "ut" = $1 ] ; then
    mvn clean verify -pl itrms/itrms-jacoco-report -am -PunitTest -Dbdgc.skip=false
elif [ "package_web" = $1 ] ; then
    cd eladmin-web
    npm install
    npm run build:prod
    tar -czf dist.tar.gz ./dist
    cp dist.tar.gz ../output
elif [ "docker_web" = $1 ] ; then
    cd eladmin-web
    npm install
    npm run build:prod
    docker exec -it itrms rm -rf /usr/share/nginx/html/*
    docker cp eladmin-web/dist/ itrms:/usr/share/nginx/html/
elif [ "package_system" = $1 ] ; then
    mvn clean package -pl eladmin-system -am -DskipTests=true -Dbdgc.skip=false
    cp eladmin-system/target/eladmin-system.jar ./output
elif [ "docker_system" = $1 ] ; then
    mvn clean package -pl eladmin-system -am -DskipTests=true -Dbdgc.skip=false
    docker cp eladmin-system/target/eladmin-system.jar itrms:/opt/eladmin-system.jar
elif [ "package_mock_server" = $1 ] ; then
    mvn clean package -pl itrms/itrms-mock-server -am -Dbdmgc.skip=false
    cp itrms/itrms-mock-server/target/itrms-mock-server.jar ./output
elif [ "clean_all" = $1 ] ; then
    mvn clean
    rm -rf output
    rm -rf itrms/itrms-bundle/src
    rm -rf itrms/itrms-bundle-mock/src
fi
echo "build done."
